// pages/zonghechaxun/zonghechaxun.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showView_a: false, //选择金额

    allList: [
      {
        qiangshu: '10万以下',
        inde: '1',

      },
      {
        qiangshu: '10-20万 ',
        inde: '2',

      },
      {

        qiangshu: '20到50万',
        inde: '3',
      },
      {

        qiangshu: '50到100万',
        inde: '4',
      },
      {
        qiangshu: '100万以上',
        inde: '5',
      },



    ],
    USER_COUPON_PHONE: '',
    chuanhsuzi: '',
    COUPON_AMOUNT:'',
    
    flag: true, //设置节流
  },


  but_shu: function (e) {

    this.setData({

      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      openid: app.globalData.openid,
      session_key: app.globalData.session_key,
      EMPLOYEE_ID: app.globalData.mealsList,
    });
    console.log(e.target.dataset.item);
    this.setData({
      COUPON_AMOUNT: e.target.dataset.item.qiangshu,
      chuanhsuzi: e.target.dataset.item.inde,
    })

    // if (this.data.COUPON_AMOUNT == e.target.dataset.item) {
    this.setData({
      showView_a: (!this.data.showView_a)
    })
    // }
  },


  jump() {
    if (this.data.flag) {

    this.data.flag = false

    if (this.data.USER_COUPON_PHON == ' ' || this.data.chuanhsuzi == '') {
      wx.showToast({
        title: '请完善信息',
        icon: 'none',
        duration: 1500
      })

    } else {


      wx.request({
        url: app.globalData.interface+'/hanzhong/API_7109_AddUserMoney',
        method: 'POST',
        data: {
          POST_SENT_HOME_PHONE: this.data.USER_COUPON_PHONE,
          USE_NUMBER: this.data.chuanhsuzi,
          EMPLOYEE_ID: this.data.EMPLOYEE_ID,
          OPEN_ID: this.data.OPEN_ID, //用户OPEN_ID
          session_key: this.data.session_key,
          OPEN_UUID: this.data.jiami
        },
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: res => {
          // console.log(res.data.allList);

          let that = this

          if (res.data.result == 'success') {
            wx.showModal({
              title: '温馨提示',
              content: res.data.data,
              success: function (res) {
                if (res.confirm) {//这里是点击了确定以后
                  console.log('用户点击确定')
                  that.setData({
                    USER_COUPON_PHONE: '',
                    COUPON_AMOUNT: '',
                    chuanhsuzi: '',
                  })

                } else {//这里是点击了取消以后
                  console.log('用户点击取消')
                  that.setData({
                    USER_COUPON_PHONE: '',
                    COUPON_AMOUNT: '',
                    chuanhsuzi: '',
                  })
                }
              }
            })
          } else {
            wx.showToast({
              title:res.data.data,
              icon: 'none',
              duration: 1500
            })

          }

        }
      })
    }
    setTimeout(() => {
      this.data.flag = true
    }, 5000)
  }
  },


 //验证手机号
 mobileInput(e) {
  let value = e.detail.value.replace(/\D/g, '')
  this.setData({
    mobile: value,
  })
  var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(15[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
  if (this.data.mobile.length == 0) {
    wx.showToast({
      title: '输入的手机号为空，请重新输入！',
      icon: 'none',
      duration: 1500
    })
    this.setData({
      mobileFormat: false,
      USER_COUPON_PHONE:'',
    })
  } else if (this.data.mobile.length < 11) {

    wx.showToast({
      title: '手机号长度有误，请重新输入！',
      icon: 'none',
      duration: 1500
    })
    this.setData({
      USER_COUPON_PHONE:'',
      mobileFormat: false,
    })

  } else if (!myreg.test(this.data.mobile)) {
    wx.showToast({
      title: '手机号有误，请重新输入！',
      icon: 'none',
      duration: 1500
    })
    this.setData({
      USER_COUPON_PHONE:'',
      mobileFormat: false,
    })

  } else {
    this.setData({
      mobileFormat: true,
    })
  }
},




  but_jq() {

    this.setData({
      showView_a: (!this.data.showView_a)
    })

  },


  tiaoa() {
    wx.navigateTo({
      url: '/pages/tuanyuanfan/tuanyuanfan',

    })
  },


  tiaob() {
    wx.navigateTo({
      url: '/pages/nanhuojie/nanhuojie',

    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})